import { createStore } from 'vuex'

export default createStore({
  state: {
    num: 0,
    dzlist: []
  },
  mutations: {
    setNum(state) {
      state.num++
    },
    setNum2(state, val) {
      state.num += val
    },
    setDzlist(state, arr) {
      state.dzlist = arr;
    }
  },
  getters: {
    totalPrice(state) {
      return state.num * 100
    }
  },
  actions: {
    getDZ(context) {
      context.commit('setDzlist', [1, 2, 3]);
      const api = 'https://api.apiopen.top/getJoke?page=1&count=5&type=text';
      // axios.get(api).then((result) => { store.setDZlist(result.data.result) });
      fetch(api).then((res) => res.json()).then(result => {
        console.log(result);
        context.commit('setDzlist', result.result);
      });
    }
  },
  modules: {

  }
})
